<!DOCTYPE html>
<%@page pageEncoding="UTF-8"%>
<html>
<!-- 
  - Author(s): waffie
  - Date: 2020-08-04 09:55:35
  - Description:
-->
<head>
<title>index</title>
<%@include file="/resource/component.jsp"%>
</head>
<body>
<div class="nui-layout" style="position:fixed;width:100%;height:100%;">
    <div class="app-header" region="north" height="70" showSplit="false" showHeader="false">
        <h1 class="logoText">管理系统</h1>
        <div class="userInfo">
        	<p id="username">欢迎回来，admin.</p>
        </div>
        <div class="search-top">
        	<input id="search" class="nui-textbox" emptyText="请输入关键字" />
        	<a class="nui-button" iconCls="icon-search">查询</a>
        	<a class="nui-button" iconCls="icon-search">高级检索</a>
        </div>
    </div>
    <div title="south" region="south" showSplit="false" showHeader="false" height="30" >
        <div style="line-height:28px;text-align:center;cursor:default">Copyright © 信息技术部 </div>
    </div>
    <div showHeader="false" region="west" width="180" maxWidth="250" minWidth="100" >
        <!-- OutlookMenu -->
        <div id="leftTree" class="nui-outlookmenu" onitemselect="onItemSelect"
            idField="id" parentField="pid" textField="text" borderStyle="border:0" expandOnLoad="false"></div>
    </div>
    <div title="center" region="center" style="border:0;" bodyStyle="overflow:hidden;">
        <!-- Tabs -->
        <div id="mainTabs" class="nui-tabs" activeIndex="0" style="width:100%;height:100%;" plain="false" onactiveclick="onTabsActiveChanged">
            <div title="首页" url="page_error/pageBuilding.jsp"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
nui.parse();

var menuData = [
		{ id: "menuSystem", text: "系统页面", iconCls: "icon-collapse"},
		{ id: "ms1", pid: "menuSystem", text: "表单", iconCls: "icon-", url: "page/pageForm.jsp" },
		{ id: "ms2", pid: "menuSystem", text: "列表", iconCls: "icon-", url: "page/pageGrid.jsp" },
		{ id: "ms3", pid: "menuSystem", text: "列表-查询框", iconCls: "icon-", url: "page/pageGridSearch.jsp" },
		{ id: "ms4", pid: "menuSystem", text: "列表-工具条", iconCls: "icon-", url: "page/pageGridToolbar.jsp" },
		{ id: "ms5", pid: "menuSystem", text: "UEditor", iconCls: "icon-", url: "page/pageUEditor.jsp" },
		{ id: "ms6", pid: "menuSystem", text: "UMEditor", iconCls: "icon-", url: "page/pageUMEditor.jsp" },
		{ id: "ms7", pid: "menuSystem", text: "form1", iconCls: "icon-", url: "page/form1.jsp" },
        { id: "ms8", pid: "menuSystem", text: "form2", iconCls: "icon-", url: "page/form2.jsp" },
		{ id: "menuExtend", text: "扩展页面", iconCls: "icon-collapse"},
		{ id: "me1", pid: "menuExtend", text: "XXX", iconCls: "icon-", url: "page/extend/XXX.jsp" },		
		{ id: "me2", pid: "menuExtend", text: "XXX", iconCls: "icon-", url: "page/extend/XXX.jsp" },
		{ id: "me3", pid: "menuExtend", text: "XXX", iconCls: "icon-", url: "page/extend/XXX.jsp" }
	];

var leftTree = nui.get("leftTree");
leftTree.loadList(menuData); 

var showTab = function(item) {
    var tabs = nui.get("mainTabs");

    var id = "tab$" + item.id;
    var tab = tabs.getTab(id);
    if (!tab) {
        tab = {};
        tab._nodeid = item.id;
        tab.name = id;
        tab.title = item.text;
        tab.showCloseButton = true;

        //这里拼接了url，实际项目，应该从后台直接获得完整的url地址
        tab.url = item.url;

        tabs.addTab(tab);
    }
    tabs.activeTab(tab);
}

var onItemSelect = function (e) {
    var item = e.item;
    showTab(item);
}

var onTabsActiveChanged = function(e) {
    var tabs = e.sender;
    var tab = tabs.getActiveTab();
    if (tab && tab._nodeid) {
        var item = leftTree.getNode(tab._nodeid);
        if (item) {
            leftTree.selectNode(item);
        }
    }
}

//页面加载时调用
$(function() {
    islogin();
})

//是否登录
function islogin() {
    $.ajax({
        url: "http://localhost:8088/User/show",
        async: false,
        success: function(data) {
            console.log(data);
            if (data.status == 201) {
                alert(data.msg);
                window.location = "http://localhost:8088/cadiExcelImpExport/login.html";
            }
            if (data.status == 200) {
                alert("欢迎你 "+data.msg);
                // alert(data.data);//用户名
                // $("#username").text(data.data);
                // selectUserAll();
                // $("#qdl").hide();
                $("#username").html("<span>欢迎你&nbsp;</span>" + data.msg+"<a onclick='logout()'>登出</a>").css('color', 'red');
                // document.getElementById("logout").style.display = "block";
                //查询所有记录
                // selectAll();
            }

        },
        error: function(e) {
            alert("出错");
            alert(e.responseText);
            window.location = "http://localhost:8088/cadiEditSoftware/login.html"
        },
    })
}
//退出
function logout() {
    $.ajax({
        url:"http://localhost:8088/User/logout",
        data:null,
        success: function(data) {
            alert("登出成功");
            window.location.reload();
        }
    })
}
</script>
</body>
</html>